﻿using System;
using System.Text;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using QzEbook.BaseView;
using QzEbook.AccessObject;
using QzEbook.Common.Emun;
using System.Collections.Specialized;
using QzEbook.View;

public partial class bookList : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        BindSitemap();
        BindData();
    }

    private void BindSitemap()
    {
        WebMaster master = this.Master as WebMaster;
        QzSiteMapNode node=new QzSiteMapNode("list.xhtml","电子书列表","所有电子书");
        master.sitemap.addChild(node);

        if (Request.Url.Query == string.Empty) return;
        
        
        string name;
        string path = Request.Url.PathAndQuery;
        if (!String.IsNullOrEmpty(Request["Cid"]))
        {
            name=Category.getName(int.Parse(Request["Cid"]));
            node = new QzSiteMapNode(path, name, name);
            master.sitemap.addChild(node);
        }
        else if (!String.IsNullOrEmpty(Request["Tid"]))
        {
            name = "所有标签";
            string tagPath = "tag.xhtml";
            node = new QzSiteMapNode(tagPath, name, name);
            master.sitemap.addChild(node);

            name = Tag.getName(int.Parse(Request["Tid"]));
            node = new QzSiteMapNode(path, name, name);
            master.sitemap.addChild(node);
        }
        

        else if (!String.IsNullOrEmpty(Request["Type"]))
        {
            switch (Request["Type"])
            {
                case "N":
                    name = "最新";
                    break;
                case "W":
                    name = "本周";
                    break;
                case "M":
                    name = "本月";
                    break;
                case "B":
                    name = "购书";
                    break;
                case "P":
                    name = "评论最多";
                    break;
                case "K":
                    name = "点击最多";
                    break;
                default:
                    name = "所有";
                    break;
            }
            node = new QzSiteMapNode(path, name, name);
            master.sitemap.addChild(node);
        }
        
    }

    private void BindData()
    {
        Control adBarRef = this.Master.FindControl("adBar");
        QzNavigator innerNav = new QzNavigator();
        innerNav.Templete = "<ul id=\"innernav\">{0}</ul>";
        innerNav.addChild(this.bindNode("最新", ViewBookAction.N.ToString()));
        innerNav.addChild(this.bindNode("本周", ViewBookAction.W.ToString()));
        innerNav.addChild(this.bindNode("本月", ViewBookAction.M.ToString()));
        innerNav.addChild(this.bindNode("购书", ViewBookAction.B.ToString()));
        innerNav.addChild(this.bindNode("评论最多", ViewBookAction.P.ToString()));
        innerNav.addChild(this.bindNode("点击最多", ViewBookAction.K.ToString()));
        Literal literal = new Literal();
        literal.Text =  innerNav.ToString();
        adBarRef.Controls.Add(literal);
    }

    private NavNode bindNode(string title,string url)
    {
        NavNode node = new NavNode(title,url);
        node.Templete = "<li><a href=\"?Type={1}\" title=\"{0}\">{0}</a></li>";
        return node;
    }
}
